package tsing.javase.clear_ifelse;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum OrderStatusEnum {
    UN_PAID("1","订单未支付"),
    PAIDED("2","订单已支付"),
    SENDED("3","订单已发货"),
    SINGED("4","订单已签收"),
    EVALUATED("5","订单已评价");

    private String status;

    private String statusDes;

    static OrderStatusEnum of(String status) {
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            if (statusEnum.getStatus().equals(status)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static void main(String[] args) {

        /**
         * 原 ：太多的if else
         */
        String orderStatusDes = "";
        String orderStatus = "1";
   /*
        if ("1".equals(orderStatus)) {
            orderStatusDes = "订单未支付";
        } else if ("2".equals(orderStatus)) {
            orderStatusDes = "订单已支付";
        } else if ("3".equals(orderStatus)) {
            orderStatusDes = "订单已发货";
        } else if ("4".equals(orderStatus)) {
            orderStatusDes = "订单已签收";
        } else if ("5".equals(orderStatus)) {
            orderStatusDes = "订单已评价";
        }*/

        /**
         * 优化后：使用枚举类型干掉 if else
         */
        orderStatusDes = OrderStatusEnum.of(orderStatus).getStatusDes();
        System.out.println(orderStatusDes);

    }
}

